package com.neusoft.student.controller;

import com.neusoft.student.model.Student;
import com.neusoft.student.service.StudentService;
import com.neusoft.student.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: duan
 * @Date: Create in 15:03 2020/10/22
 */
@WebServlet("/studenttoedit")
public class StudentToEditServlet extends HttpServlet {
    private StudentService studentService = new StudentServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("StudentToEditServlet:::doPost");
        String id = req.getParameter("id");
        Student bean = studentService.getById(Integer.valueOf(id));
        req.setAttribute("editBean", bean);
        req.getRequestDispatcher("/student_edit.jsp").forward(req, resp);
    }
}
